package com.edu.service.impl;

import com.edu.dao.EduMenuMapper;
import com.edu.pojo.EduMenu;
import com.edu.service.EduMenuService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 菜单服务层
 *
 * @author YJF
 */
@Service
public class EduMenuServiceImpl implements EduMenuService {

    @Autowired
    private EduMenuMapper eduMenuMapper;

    @Override
    public List<EduMenu> findAll() {
        return eduMenuMapper.selectAll();
    }

    @Override
    public List<EduMenu> findMenu() {
        EduMenu parent = new EduMenu();
        parent.setParentId(0);
        List<EduMenu> firstGrade = eduMenuMapper.select(parent);
        for (EduMenu menu : firstGrade) {
            EduMenu children = new EduMenu();
            children.setParentId(menu.getMenuId());
            List<EduMenu> secondGrade = eduMenuMapper.select(children);
            menu.setChildren(secondGrade);
        }
        return firstGrade;
    }
}
